//
//  PhotoCollectionView.m
//  Project1
//
//  Created by 黄珂耀 on 15/7/23.
//  Copyright (c) 2015年 黄珂耀. All rights reserved.
//

#import "PhotoCollectionView.h"
#import "PhotoCollectionViewCell.h"

@implementation PhotoCollectionView

- (id)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self)
    {
        [self _createPhotoCollectionView];
    }
    return self;
}

- (void)setPhotoURLArray:(NSArray *)photoURLArray
{
    _photoURLArray = photoURLArray;
}

- (void)_createPhotoCollectionView
{
    self.dataSource = self;
    self.delegate = self;
 
    self.pagingEnabled = YES;
    
    _photoCollectionViewCell = [[PhotoCollectionViewCell alloc] initWithFrame:self.bounds];
    
    [self registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [_photoURLArray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.photoURL = _photoURLArray[indexPath.row];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCollectionViewCell *collectionCell = (PhotoCollectionViewCell *)cell;
    
    PhotoScrollView *scrollView = (PhotoScrollView *)[collectionCell viewWithTag:100];
    
    scrollView.zoomScale = 1;
}







/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
